package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.BusinessPojo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.paas.field.SerialNumberPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.ProductNotifyEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.dictionary.ProductUnitEnum;
import com.xbongbong.saas.script.help.SaasInitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author Jian.Wang
 * @date 2019/
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum TempProductEnum {
    // 产品
    BASE_INFO(ProductEnum.BASE_INFO),
    NAME(ProductEnum.NAME),
    SERIALNO(ProductEnum.SERIALNO),
    PRODUCT_NO(ProductEnum.PRODUCT_NO),
    BARCODE(ProductEnum.BARCODE),
    PRODUCT_IMGS(ProductEnum.PRODUCT_IMGS),
    CATEGORY_ID(ProductEnum.CATEGORY_ID),
    LABEL(ProductEnum.LABEL),
    ENABLE_MULTI_UNIT(ProductEnum.ENABLE_MULTI_UNIT),
    UNIT(ProductEnum.UNIT),
    PRICE(ProductEnum.PRICE),
    COST(ProductEnum.COST),
    STOCK(ProductEnum.STOCK),
    INSTRUCTION(ProductEnum.INSTRUCTION),
    VISBLE_DEPT(ProductEnum.VISBLE_DEPT),
    VISBLE_USER(ProductEnum.VISBLE_USER),
    ATTACHMENT(ProductEnum.ATTACHMENT),

    SPECIFICATION_INFO(ProductEnum.SPECIFICATION_INFO),
    SPECIFICATION(ProductEnum.SPECIFICATION),
    WAREHOUSE_INFO(ProductEnum.WAREHOUSE_INFO),
    WAREHOUSE(ProductEnum.WAREHOUSE),
    STOCK_INFO(ProductEnum.STOCK_INFO),
    IS_NOTIFY(ProductEnum.IS_NOTIFY),
    STOCK_NOTIFY(ProductEnum.STOCK_NOTIFY),


    ASSOCIATED_INFO(ProductEnum.ASSOCIATED_INFO),
    SUPPLIER(ProductEnum.SUPPLIER),

    BATCH_SHELF_LIFE_MANAGEMENT(ProductEnum.BATCH_SHELF_LIFE_MANAGEMENT),
    ENABLE_BATCH_SHELF_LIFE(ProductEnum.ENABLE_BATCH_SHELF_LIFE),
    SHELF_LIFE_DAYS(ProductEnum.SHELF_LIFE_DAYS),
    EXPIRATION_ALERT_DAYS(ProductEnum.EXPIRATION_ALERT_DAYS),
    SERIAL_NUMBER_MANAGEMENT(ProductEnum.SERIAL_NUMBER_MANAGEMENT),
    ENABLE_SERIAL_NUMBER(ProductEnum.ENABLE_SERIAL_NUMBER),

    SYSTEM_INFO(ProductEnum.SYSTEM_INFO),
    CREATOR_ID(ProductEnum.CREATOR_ID),
    ADD_TIME(ProductEnum.ADD_TIME),
    UPDATE_TIME(ProductEnum.UPDATE_TIME),
    ONLINE_TIME(ProductEnum.ONLINE_TIME),

    SPECIFICATION_LINK_TEXT(ProductEnum.SPECIFICATION_LINK_TEXT),
    SUPPLIER_LINK_TEXT(ProductEnum.SUPPLIER_LINK_TEXT),
    // 关联仓库的隐藏字段
    WAREHOUSE_LINK_TEXT(ProductEnum.WAREHOUSE_LINK_TEXT),
    PARENT_ID(ProductEnum.PARENT_ID),
    THUMBNAIL(ProductEnum.THUMBNAIL),
    ONLINE(ProductEnum.ONLINE),
    SHOW_PRICE(ProductEnum.SHOW_PRICE),
    SHOW_COST(ProductEnum.SHOW_COST),
    ORI_STOCK(ProductEnum.ORI_STOCK),
    STOCK_UPPER_LIMIT(ProductEnum.STOCK_UPPER_LIMIT),
    STOCK_LOWER_LIMIT(ProductEnum.STOCK_LOWER_LIMIT),
    TEMP_STOCK(ProductEnum.TEMP_STOCK),


    ;
    private ProductEnum anEnum;

    TempProductEnum(ProductEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempProductEnum> getAllEnum() {
        List<TempProductEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initStock(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setMemo("更改此设置，关联单据设置会一并更改");
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias()));
    }

    public static void initName(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PRODUCT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(NAME.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化产品编号
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSerialNo(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PRODUCT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SERIALNO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
        SerialNumberPoJo serialNumberPoJo = SaasInitExplainsHelper.setSerialNumber(SerialNumberEnum.PRODUCT_NO);
        fieldAttrEntity.setSerialNumber(serialNumberPoJo);

    }
    /**
     * 初始化关联供应商 -- 多选
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSupplier(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setLinkedText(SUPPLIER_LINK_TEXT.getAnEnum().getAttr());
    }
    /**
     * 初始化单位
     *
     * @param  fieldAttrEntity 实体
     * @author Jian.Wang
     * @since v1.0
     */
    public static void initProductUnit(FieldAttrEntity fieldAttrEntity) {
//        String str = "kg,g,件,千克,个,盒";
        fieldAttrEntity.setItems(SaasInitExplainsHelper.setCombItemByEnum(ProductUnitEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }
    /**
     * 初始化条码字段
     *
     * @param  fieldAttrEntity 实体
     * @author lcx
     * @since v1.0
     */
    public static void initBarcode(FieldAttrEntity fieldAttrEntity) {
        // 走自己写的查重逻辑，不走paas原查重逻辑
        fieldAttrEntity.setNoRepeat(0);
    }

    public static void initPrice(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setMemo("更改此设置，关联单据设置会一并更改");
    }


    public static void initCost(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setMemo("更改此设置，关联单据设置会一并更改");
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initOnlineTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initSales(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initSpecification(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(1);
        fieldAttrEntity.setVisibleAdvancedForbidden(0);
        fieldAttrEntity.setVisibleScopeEnable(0);
    }

    /**
    * @Description: 关联仓库
    * @Param: [fieldAttrEntity]
    * @return: void
    * @Author: cyy
    * @Date: 2019/9/9
    */
    public static void initWarehouse(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(WAREHOUSE_LINK_TEXT.getAnEnum().getAttr());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setVisibleAdvancedForbidden(0);
    }
    /**
    * @Description:
    * @Param: [fieldAttrEntity]
    * @return: void
    * @Author: cyy
    * @Date: 2019/10/21
    */
    public static void initStockNotify(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity specification = SaasInitExplainsHelper.setField("array_1", "规格", "specification", FieldTypeEnum.CASCADER.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        specification.setRequired(1);
        specification.setDictionaryFlag(1);
        specification.setParentAttr(STOCK_NOTIFY.anEnum.getAttr());
        items.add(specification);

        FieldAttrEntity warehouseName = SaasInitExplainsHelper.setField(ProductNotifyEnum.WAREHOUSE_NAME.getAttr(), "仓库名称", "warehouseName", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        warehouseName.setNoRepeat(0);
        warehouseName.setParentAttr(STOCK_NOTIFY.anEnum.getAttr());
        warehouseName.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        warehouseName.setRequired(1);
        // 默认的查询范围
        BusinessPojo businessPojo = new BusinessPojo();
        businessPojo.setAllWarehouse(1);
        warehouseName.setBusinessPojo(businessPojo);
        items.add(warehouseName);

        FieldAttrEntity stockMin = SaasInitExplainsHelper.setField("num_3", "最低库存", "stockLowerLimit", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        stockMin.setNoRepeat(0);
        stockMin.setParentAttr(STOCK_NOTIFY.anEnum.getAttr());
        stockMin.setRequired(1);
        NumericalLimitsPoJo numericalLimitsPoJo = new NumericalLimitsPoJo();
        numericalLimitsPoJo.setMin(0D);
        numericalLimitsPoJo.setMax(9007199254740991D);
        stockMin.setNumericalLimits(numericalLimitsPoJo);
        stockMin.setNumericalLimitsFlag(0);
        items.add(stockMin);

        FieldAttrEntity stockMax = SaasInitExplainsHelper.setField("num_4", "最高库存", "stockUpperLimit", FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        stockMax.setNoRepeat(0);
        stockMax.setParentAttr(STOCK_NOTIFY.anEnum.getAttr());
        stockMax.setRequired(1);
        NumericalLimitsPoJo maxNumber = new NumericalLimitsPoJo();
        maxNumber.setMin(0D);
        maxNumber.setMax(9007199254740991D);
        stockMax.setNumericalLimits(maxNumber);
        stockMax.setNumericalLimitsFlag(0);
        items.add(stockMax);

        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        fieldAttrEntity.setRequired(0);
        fieldAttrEntity.setDictionaryFlag(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setVisibleAdvancedForbidden(0);
    }



    public static void initVisbleDept(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initVisbleUser(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setIsForbidden(0);

    }
    /**
     * 关联库存预警子表单和按钮
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initIsNotify(FieldAttrEntity fieldAttrEntity){
        List<String> switchMap = new ArrayList<>();
        switchMap.add(STOCK_NOTIFY.anEnum.getAttr());
        fieldAttrEntity.setSwitchMap(switchMap);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setVisibleAdvancedForbidden(0);
    }

    /**
     * 是否启用多单位
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initEnableMultiUnit(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(0);
        List<String> forbiddenSettingEnums = Collections.singletonList(ForbiddenSettingEnum.DISABLE_VISIBLE_PERMISSION.getAlias());
        fieldAttrEntity.setForbiddenSettingList(forbiddenSettingEnums);
    }

    /**
     * 关联批次保质期子表单和按钮
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initEnableBatchShelfLife(FieldAttrEntity fieldAttrEntity){
        List<String> switchMap = new ArrayList<>();
        switchMap.add(SHELF_LIFE_DAYS.anEnum.getAttr());
        switchMap.add(EXPIRATION_ALERT_DAYS.anEnum.getAttr());
        fieldAttrEntity.setSwitchMap(switchMap);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setVisibleAdvancedForbidden(0);
    }

    public static void initBatchShelfLifeManagement(FieldAttrEntity fieldAttrEntity){
        List<String> forbiddenSettingEnums = Arrays.asList(ForbiddenSettingEnum.DISABLE_VISIBLE_PERMISSION.getAlias());
        fieldAttrEntity.setForbiddenSettingList(forbiddenSettingEnums);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initSerialNumberManagement(FieldAttrEntity fieldAttrEntity){
        List<String> forbiddenSettingEnums = Arrays.asList(ForbiddenSettingEnum.DISABLE_VISIBLE_PERMISSION.getAlias());
        fieldAttrEntity.setForbiddenSettingList(forbiddenSettingEnums);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initEnableSerialNumber(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initExpirationAlertDays(FieldAttrEntity fieldAttrEntity){
        List<String> forbiddenSettingEnums = Arrays.asList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias(), ForbiddenSettingEnum.DISABLE_SUMMARY.getAlias(), ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias());
        fieldAttrEntity.setForbiddenSettingList(forbiddenSettingEnums);
        fieldAttrEntity.setAccuracy(0);
        fieldAttrEntity.setSummaryFlag(0);
        fieldAttrEntity.setNumAccuracyAndScopeHide(1);
        fieldAttrEntity.setIntegerOnly(1);
        NumericalLimitsPoJo numericalLimitsPoJo = new NumericalLimitsPoJo();
        numericalLimitsPoJo.setMin(0D);
        numericalLimitsPoJo.setMax(36500D);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setNumericalLimits(numericalLimitsPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }
    public static void initShelfLifeDays(FieldAttrEntity fieldAttrEntity){
        List<String> forbiddenSettingEnums = Arrays.asList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias(), ForbiddenSettingEnum.DISABLE_SUMMARY.getAlias(), ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setForbiddenSettingList(forbiddenSettingEnums);
        fieldAttrEntity.setNumAccuracyAndScopeHide(1);
        fieldAttrEntity.setSummaryFlag(0);
        fieldAttrEntity.setMemo("保质期天数为空时表示该产品不启用保质期管理");
        fieldAttrEntity.setAccuracy(0);
        fieldAttrEntity.setIntegerOnly(1);
        NumericalLimitsPoJo numericalLimitsPoJo = new NumericalLimitsPoJo();
        numericalLimitsPoJo.setMin(0D);
        numericalLimitsPoJo.setMax(36500D);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setNumericalLimits(numericalLimitsPoJo);
    }
}
